package com.oocl.homework.format.comparator;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

import com.oocl.homework.format.moel.Customer;

public class CustomerBirthdayComparator implements Comparator<Customer>{

	public int compare(Customer o1, Customer o2) {
		if (o1.getBirthday()==null||o2.getBirthday()==null) {
			if (o1.getBirthday()==null||o2.getBirthday()==null) {
				return -1;
			}
			if(o1.getBirthday()==null){
				return -1;
			}
			if(o2.getBirthday()==null){
				return 1;
			}
		}
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date1;
		Date date2;
		try {
			date1 = dateFormat.parse(o1.getBirthday());
			date2 = dateFormat.parse(o2.getBirthday());
			int t = date1.compareTo(date2);
			return t==0?-1:t;
		} catch (ParseException e) {
			
			// log here
			System.out.println("hhehe");
			e.printStackTrace();
		}
		
		return 1;
	}

}
